// Fill out your copyright notice in the Description page of Project Settings.


#include "UserWidget/WidgetComponent/LocationObjectivesWidget.h"
#include "UserWidget/WidgetComponent/SingleObjectiveHintWidget.h"
#include "UserWidget/WidgetComponent/SingleHintWidget.h"
#include "Components/VerticalBox.h"

void ULocationObjectivesWidget::ConstructWidget(TSubclassOf<USingleObjectiveHintWidget> LSingleObjectiveHintWidget, TSubclassOf<USingleHintWidget> LSingleHintWidget) {
	SingleObjectiveHintWidget = LSingleObjectiveHintWidget;
	SingleHintWidget = LSingleHintWidget;
}

void ULocationObjectivesWidget::UpdateLocationObjectives(FLocationObjectiveMaster LLocationObjective)
{
	LocationObjective = LLocationObjective;
	ObjectiveList->ClearChildren();
	for (int32 i = 0; i < LocationObjective.Objectives.Num(); ++i) {
		USingleObjectiveHintWidget* Temp = Cast<USingleObjectiveHintWidget>(CreateWidget(this, SingleObjectiveHintWidget));
		if (Temp) {
			Temp->ConstructWidget(LocationObjective.Objectives[i].ObjectiveLayout.ObjectiveTitle, LocationObjective.Objectives[i].ObjectiveLayout.Hints, SingleHintWidget);
			ObjectiveList->AddChildToVerticalBox(Temp);
			ObjectivesList.Add(Temp);
			Temp->UpdateTextColor(false);
		}
	}
}

USingleObjectiveHintWidget* ULocationObjectivesWidget::FindInObjectiveList(FText ObjectiveTitle)
{
	for (int32 i = 0; i < ObjectivesList.Num(); ++i) {
		if (ObjectivesList[i]->ObjectiveText.EqualTo(ObjectiveTitle)) {
			return ObjectivesList[i];
		}
	}
	return nullptr;
}
